// pages/shopping/comfirmOrder/comfirmOrder.js
const api = require('../../../utils/api.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    address: {},
    itemList: [],
    cartTotal: {},
    payAnimation: '',
    shadow: false
  },

  // 确认订单
  confirmOrder: function () {
    var animation = wx.createAnimation({
      duration: 500,
      timingFunction: 'linear'
    })
    this.animation = animation
    animation.bottom(0).step()
    this.setData({
      payAnimation: animation.export(),
      shadow: true
    })
  },

  // 隐藏阴影
  hideShadow: function () {
    this.animation.bottom('-50%').step()
    this.setData({
      shadow: false,
      payAnimation: this.animation.export()
    })
  },

  // 选择地址
  selectAddress: function () {
    wx.navigateTo({
      url: '../../Address/selectAdd/selectAdd',
    })
  },

  // 付款，确认订单
  pay: function (e) {
    //地址id，优惠券id
    var token = wx.getStorageSync('useof').token
    wx.request({
      url: api.api.addressList,
      header: {
        'X-Nideshop-Token': token
      },
      success: function (res) {
        console.log('order', res)
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var pages = getCurrentPages()
    var item = pages[pages.length - 2].data.itemList.filter((item, index) => {
      return item.checked == 1
    })
    var address = wx.getStorageSync('newAddress')
    this.setData({
      itemList: item,
      cartTotal: pages[pages.length - 2].data.cartTotal,
      address: address
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})